Telegram Group & Telegram Channel
💭 Холивар: f-строки vs .format() vs %

Python предлагает сразу три способа форматирования строк — и у каждого есть свои фанаты.

Разбираемся по фактам:

🔎 f-строки (Python 3.6+):
name = "Alice"
age = 30
print(f"{name} is {age} years old.")


читаемо, лаконично
быстрее при выполнении
🙅‍♂️ не работает в Python < 3.6
🙅‍♂️ неудобно при кавычках внутри строк

🔎 .format():
name = "Alice"
age = 30
print("{} is {} years old.".format(name, age))


кросс-версионно (Python 2.7+ и 3.x)
хорош для шаблонов и повторов
🙅‍♂️ длиннее, особенно с ключами
🙅‍♂️ легко запутаться с порядком аргументов

🔎 Cтарый стиль %:
name = "Alice"
age = 30
print("%s is %d years old." % (name, age))


кратко для простых случаев
работает даже в старом Python
🙅‍♂️ типобезопасность на минималках
🙅‍♂️ легко сломать, особенно при refactoring’е

Выбор зависит от контекста:
🔘 f-строки — выбор для современного Python-кода
🔘 .format() — для совместимости и шаблонов
🔘 % — для ностальгирующих и логов

А вы что используете чаще всего?

❤️ f-строки — будущее уже здесь
👍 .format() / % — стабильность и привычка

P.S. Инструкция, как оставить коммент

Библиотека питониста #междусобойчик
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/pyproglib/6775
Create:
Last Update:

💭 Холивар: f-строки vs .format() vs %

Python предлагает сразу три способа форматирования строк — и у каждого есть свои фанаты.

Разбираемся по фактам:

🔎 f-строки (Python 3.6+):

name = "Alice"
age = 30
print(f"{name} is {age} years old.")


читаемо, лаконично
быстрее при выполнении
🙅‍♂️ не работает в Python < 3.6
🙅‍♂️ неудобно при кавычках внутри строк

🔎 .format():
name = "Alice"
age = 30
print("{} is {} years old.".format(name, age))


кросс-версионно (Python 2.7+ и 3.x)
хорош для шаблонов и повторов
🙅‍♂️ длиннее, особенно с ключами
🙅‍♂️ легко запутаться с порядком аргументов

🔎 Cтарый стиль %:
name = "Alice"
age = 30
print("%s is %d years old." % (name, age))


кратко для простых случаев
работает даже в старом Python
🙅‍♂️ типобезопасность на минималках
🙅‍♂️ легко сломать, особенно при refactoring’е

Выбор зависит от контекста:
🔘 f-строки — выбор для современного Python-кода
🔘 .format() — для совместимости и шаблонов
🔘 % — для ностальгирующих и логов

А вы что используете чаще всего?

❤️ f-строки — будущее уже здесь
👍 .format() / % — стабильность и привычка

P.S. Инструкция, как оставить коммент

Библиотека питониста #междусобойчик

BY Библиотека питониста | Python, Django, Flask




Share with your friend now:
tg-me.com/pyproglib/6775

View MORE
Open in Telegram


Библиотека питониста | Python Django Flask Telegram | DID YOU KNOW?

Date: |

Telegram auto-delete message, expiring invites, and more

elegram is updating its messaging app with options for auto-deleting messages, expiring invite links, and new unlimited groups, the company shared in a blog post. Much like Signal, Telegram received a burst of new users in the confusion over WhatsApp’s privacy policy and now the company is adopting features that were already part of its competitors’ apps, features which offer more security and privacy. Auto-deleting messages were already possible in Telegram’s encrypted Secret Chats, but this new update for iOS and Android adds the option to make messages disappear in any kind of chat. Auto-delete can be enabled inside of chats, and set to delete either 24 hours or seven days after messages are sent. Auto-delete won’t remove every message though; if a message was sent before the feature was turned on, it’ll stick around. Telegram’s competitors have had similar features: WhatsApp introduced a feature in 2020 and Signal has had disappearing messages since at least 2016.

Export WhatsApp stickers to Telegram on iPhone

You can’t. What you can do, though, is use WhatsApp’s and Telegram’s web platforms to transfer stickers. It’s easy, but might take a while.Open WhatsApp in your browser, find a sticker you like in a chat, and right-click on it to save it as an image. The file won’t be a picture, though—it’s a webpage and will have a .webp extension. Don’t be scared, this is the way. Repeat this step to save as many stickers as you want.Then, open Telegram in your browser and go into your Saved messages chat. Just as you’d share a file with a friend, click the Share file button on the bottom left of the chat window (it looks like a dog-eared paper), and select the .webp files you downloaded. Click Open and you’ll see your stickers in your Saved messages chat. This is now your sticker depository. To use them, forward them as you would a message from one chat to the other: by clicking or long-pressing on the sticker, and then choosing Forward.

Библиотека питониста | Python Django Flask from us


Telegram Библиотека питониста | Python, Django, Flask
FROM USA